<template>
 <!--查看弹框start-->
            <div>
            <!-- <h1>新增商城孵化申请信息</h1> -->
            <el-form >
              <el-form-item >
                  <el-button type="primary" @click="handlerPage" size="small"> 查询商城</el-button>
              </el-form-item>
                
                <el-form-item label-width="80px" label="商城信息" style="background: #e1e1e1"></el-form-item>
                <el-form-item label-width="40px">
                    <el-form-item label-width="100px" label="商城账号：" style="width:50%;display: inline-block;">
                        <span >{{tableData.usermobile }}</span>
                        
                    </el-form-item>
                    <el-form-item label="商城公司名称：" style=" margin-left: 20px; width:30%;display: inline-block;">
                         <span  >{{tableData.enterprisename}}</span>
                        
                    </el-form-item>
                </el-form-item>

                <el-form-item label-width="100px" label="孵化信息" style="background: #e1e1e1"/>
                 <el-form-item label="孵化公司级别：" class="query-form-item">
                    <el-select v-model="query.companyLevel"  placeholder="请选择孵化公司级别："  clearable>
                    <el-option label="全部" value></el-option>
                    <el-option label="县级公司" value="4"></el-option>
                    <el-option label="市级公司" value="3"></el-option>
                    <el-option label="省级公司" value="2"></el-option>
                    <el-option label="全球公司" value="1"></el-option>
                    </el-select>
                 </el-form-item>

                 <el-form :model="query" :rules="rules">
                  <el-form-item label="孵化报名时间：" class="query-form-item" prop="value">
                     <el-date-picker v-model="query.value"   type="date" placeholder="选择日期"  @change="onChange" format="yyyy-MM-dd" :clearable="false">  </el-date-picker>
                  </el-form-item>
                 </el-form>
                 <el-form-item label="孵化预备期：" class="query-form-item" :inline="true">
                    <el-date-picker v-model="query.value1"   type="date" start-placeholder="选择日期"   format="yyyy-MM-dd" disabled>  </el-date-picker>至
                    <el-date-picker v-model="query.value2"   type="date" start-placeholder="选择日期"   format="yyyy-MM-dd" disabled>  </el-date-picker>
                 </el-form-item>
                

                <el-form-item >
                  <el-button type="primary" @click="onSubmit" size="small"> 新增</el-button>
                </el-form-item>
            </el-form>
</div>
</template>

<script>
   import {getRules,addRules} from "../../api/incubationrules/index.js";
import incubationStepVue from './incubationStep.vue';
  export default {
    data() {
      return {
        tableData: {},//列表对象
        query:{
          companyLevel:"",//孵化公司级别
          value:"",//补报名的选择时间
          userid:"",//商城id
          value1:"",//回显的时间
          value2:"",
          preparatoryPeriod:"",//设定的时间规则制度
          company:"",//公司名称
        },
      
        rules: {
            value:[{
            required: true,
            message: "请选择孵化报名时间",
            trigger: "change"
            }] 
        }
      }
    },
    methods: {
      getRules(){
        getRules()
        .then(res=>{
            console.log(res.data.preparatoryPeriod)
            this.query.preparatoryPeriod = res.data.preparatoryPeriod
        })
      },
      //查询商城页面跳转
      handlerPage(){
        this.$router.push({path:"searchEntity"})
      },
      //提交信息
       onChange(val) {
        let date = new Date(val)
        let y = date.getFullYear()
        let m = date.getMonth() + 1
        m = m < 10 ? ('0' + m) : m
        let d = date.getDate()
        d = d < 10 ? ('0' + d) : d
        const time =  y + '-' + m + '-' + d;
        this.value=time;
        console.log(this.value) 
        if(this.query.value !==""){
            let date = new Date(val);//没有传入值时,默认是当前日期
            date = date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate();
            date += " 00:00:00";//设置为当天凌晨12点
            date = Date.parse(new Date(date))/1000;//转换为时间戳
            date += (86400) * 1;//修改后的时间戳
            var newDate = new Date(parseInt(date) * 1000);//转换为时间
             let m = newDate.getMonth() + 1
             m = m < 10 ? ('0' + m) : m
             let d = newDate.getDate()
             d = d < 10 ? ('0' + d) : d
            const time1 = newDate.getFullYear() + '-' + m + '-' + d;
            this.query.value1 =time1
            console.log(this.query.value1)

            let date2 = new Date(val);//没有传入值时,默认是当前日期
            date2 = date2.getFullYear() + '-' + (date2.getMonth() + 1) + '-' + date2.getDate();
            date2 += " 00:00:00";//设置为当天凌晨12点
            date2 = Date.parse(new Date(date2))/1000;//转换为时间戳
            date2 += (86400) * this.query.preparatoryPeriod;//修改后的时间戳
            var newDate2 = new Date(parseInt(date2) * 1000);//转换为时间
            let m2 = newDate2.getMonth() + 1
             m2 = m2 < 10 ? ('0' + m2) : m2
             let d2 = newDate2.getDate()
             d2 = d2 < 10 ? ('0' + d2) : d2
            const time2 = newDate2.getFullYear() + '-' + m2 + '-' + d2;
              console.log(time2)
            this.query.value2 =time2
           
           
        }else{
            this.query.value1=""
            this.query.value2=""
        }
      }, 
      onSubmit(){
          let data ={
            userId:this.query.userid,
            preparatoryPeriod:this.query.preparatoryPeriod,
            applyTime:this.query.value,
            
            companyLevel:this.query.companyLevel,
            company:this.query.company
          }
         
          if(this.tableData.usermobile !=="" && this.query.value !=="" && this.query.companyLevel !=="" ){
            addRules(data).then(res=>{
                console.log(res)
                let _this =this
              if(res.code ===7){
                  this.$message.error(res.message)
              }else{
                  this.$message.success(res.data)
                  if(res.code ===0){
                  _this.$router.push({path:"incubationStep"})
                  }
                  
              }
            })
          }else{
              this.$message.warning("请选择商城账号和商城公司以及孵化公司名称或者报名时间")

          }
        
      }
     
      
    },
    created(){
        this.getRules()
        console.log(this.$route.query.data)
        let that =this
        this.$nextTick(() => {
           that.tableData =that.$route.query.data || {}  
           that.query.userid =that.tableData.userid ||""  
           that.query.company =that.tableData.enterprisename ||"" 
           console.log(that.query.userid) 
      });
       
    },
    mounted(){
        
    }

   

  }
</script>